package com.androidtestintent2.intent2;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaCodec;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {
    String pn = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button btn = (Button) findViewById(R.id.button);
        final EditText et = (EditText) findViewById(R.id.editText);
        btn.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View view) {
                pn = et.getText().toString();
                if (PhoneNumberUtils.isGlobalPhoneNumber(pn)) {
                    Intent it = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + pn));
                    startActivity(it);
                }else{
                    Toast.makeText(MainActivity.this,"您输入的号码不正确，请重新输入",Toast.LENGTH_LONG).show();
                }

            }
        });
    }
}
